package cn.wolfcode.web.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 拦截器类
 * <p>
 * 登录拦截
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 登录拦截
        HttpSession session = request.getSession();
        Object user = session.getAttribute("EMPLOYEE_IN_SESSION");
        if (user == null) {
            response.sendRedirect("/static/login.html");
            return false;
        }
        return true;
    }
}
